<?php

require_once 'FWidget.class.php';

class FSelection extends FWidget
{
    
    
    private $valueColumn;
    
    private $displayColumn;
    
    private $emptyText;
    
    const EMPTY_TEXT = ' --- Selecione --- ';

    public function __construct($name, $fieldLabel = '', $valueColumn = 'codigo', $displayColumn = 'descricao', $fieldWidth = 20, $emptyText = '')
    {
        parent::__construct($name, 'fselection', $fieldLabel, $fieldWidth);
        $this->setValueColumn($valueColumn);
        $this->setDisplayColumn($displayColumn);
        $this->setEmptyText($emptyText);
        $this->setIsInput(true);
    }
    
    public function generate()
    {        
        $storeFields = "'" . $this->getValueColumn() . "','" . $this->getDisplayColumn() . "'";
        $emptyText = strlen($this->getEmptyText() > 0 ) ? $this->getEmptyText() : self::EMPTY_TEXT;
        $allowBlank = $this->getRequired() ? 'false' : 'true';
        
        return "{
            xtype: '{$this->getXtype()}',
            hiddenName: '{$this->getName()}',
            name: '{$this->getName()}', 
            fieldLabel: '{$this->getFieldLabel()}',
            table: '{$this->getTable()}',
            storeFields: [$storeFields],
            valueField: '{$this->getValueColumn()}',
            displayField: '{$this->getDisplayColumn()}',
            className: '{$this->getClassName()}',
            storeParam: 'list',
            fieldWidth: {$this->getFieldWidth()},
            emptyText: '$emptyText',
            allowBlank: $allowBlank
        }";
    }

    public function getValueColumn() {
        return $this->valueColumn;
    }

    public function setValueColumn($valueColumn) {
        $this->valueColumn = $valueColumn;
    }

    public function getDisplayColumn() {
        return $this->displayColumn;
    }

    public function setDisplayColumn($displayColumn) {
        $this->displayColumn = $displayColumn;
    }
    
    public function getEmptyText() {
        return $this->emptyText;
    }

    public function setEmptyText($emptyText) {
        $this->emptyText = $emptyText;
    }

}


?>
